from django.http import HttpResponse
from django.shortcuts import render

# Create your views here.
from django.template import loader, context

from Three.models import Student, Grade


def index(request):
    threeindex = loader.get_template('threeindex.html')

    context = {
        "student_name" : "Extra"
    }

    result = threeindex.render(context=context)
    print(result)

    return HttpResponse(result)


def getGrade(request):

    #数据集连1 通过同学赵所在班级
    student = Student.objects.get(pk=2)
    grade = student.s_Grade
    return HttpResponse("Grade is %s,Student is : %s " % (grade.g_name,student.s_name))


def getStudent(request):
    # 数据集连2 通过班级找班级中的所有同学
    grade = Grade.objects.get(pk=1)

    #获取到student集合
    students = grade.student_set.all()
    context = {
        "students" : students
    }
    return render(request,"student_three_list.html",context=context)
